//
//  DebugPathLogWindow.m
//  YK_DebugManager
//
//  Created by edward on 2021/5/12.
//

#import "DebugPathLogWindow.h"
#import "DebugPathLogViewController.h"

@interface DebugPathLogWindow ()

@end

@implementation DebugPathLogWindow

static DebugPathLogWindow *_instance;

+ (id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });

    return _instance;
}

+ (instancetype)sharedInstance
{
    if (_instance == nil) {
        _instance = [[DebugPathLogWindow alloc] initWithFrame:CGRectMake(10, [UIApplication sharedApplication].statusBarFrame.size.height + 5, UIScreen.mainScreen.bounds.size.width - 20, 200)];
    }

    return _instance;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.windowLevel = UIWindowLevelStatusBar + 3.0f;
    }
    return self;
}

- (void)show
{
    [super show];
    __weak typeof(self) weakself = self;
    DebugPathLogViewController *vc = [[DebugPathLogViewController alloc] initWithDissMissBlock:^{
        [weakself dissMiss];
    }];
    self.vc = vc;
    self.rootViewController = vc;
}
- (void)dissMiss
{
    [super dissMiss];
}

- (void)addLogText:(NSString *)text
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [((DebugPathLogViewController *)self.rootViewController) addLogText:text];
    });
}

@end
